#include "PacketHelper.hpp"

/**
 * Create ServerEntityLocation packet.
 */
Packet_ServerEntityLocation PacketHelper::ServerEntityLocation(const Entity* entity){
	Packet_ServerEntityLocation packet;
	packet.direction = entity->direction;
    packet.x = entity->x;
	packet.y = entity->y;
    packet.client = entity->index;
	return packet;
}

/**
 * Create packet for the state of an Entity.
 */
Packet_EntityState PacketHelper::EntityState(const Entity* entity){
	Packet_EntityState packet;
	packet.index = entity->index;
    strncpy(packet.script, entity->script, OBJECT_SCRIPT_LENGTH);
    
	packet.x = entity->x;
	packet.y = entity->y;
	packet.direction = entity->direction;
	return packet;
}

/**
 * Create Chat message packet.
 */
Packet_ChatMessage PacketHelper::ChatMessage(const char* message, byte client){
	Packet_ChatMessage packet;
	packet.client = client;
	strncpy(packet.message, message, CHAT_MESSAGE_LEN);
	packet.message[CHAT_MESSAGE_LEN] = 0;
	return packet;
}

/**
 * Create packet containing full state of a client.
 */
Packet_ClientState PacketHelper::ClientState(const Entity* client, const char* name){
	Packet_ClientState packet;
	strncpy(packet.name, name, CLIENT_NAME_LEN);
	packet.name[CLIENT_NAME_LEN] = 0;
	packet.client = (uint8_t)client->index;
	packet.direction = client->direction;
	packet.x = client->x;
	packet.y = client->y;
	return packet;
}